/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PCR;

import Enums.ProjectType;
import components.*;
import components.shape.Shape;
import components.shape.ShapeFocusHandler;
import components.shape.ShapeMouseAction;
import components.shape.ShapeMouseMotionAction;
import components.shapemenu.CheckMenuAction;
import components.shapemenu.MenuAction;
import components.shapemenu.ShapeMenuActions;
import graphics.PrintPreviewer;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.beans.PropertyVetoException;
import java.io.*;
import java.util.Scanner;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.undo.UndoManager;
import org.jfree.ui.RefineryUtilities;
import utilities.CustomFileChooser;
import utilities.DualAxisChart;
import utilities.ExtensionFileFilter;
import utilities.ImagePrinter;

/**
 * This class is the main class of the application where creation of the main
 * frame and handling common functions
 *
 * @author asmaa
 */
public class MainFrame extends javax.swing.JFrame {

    //This is the Class Variables
    private String showInputDialog;
    NewPCR pcr;
    Toolbox toolBox;
    NewSequencer seq;
    NewPro Newprotein;
    Shape selected;
    String openImagePath;
    final UndoManager undo = new UndoManager();
    private String inputDialog;

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
        this.setResizable(true);
        toolBox = new Toolbox();
        toolBox.setVisible(true);
        toolBox.setSize(200, 600);
        toolBox.setLocation(10, 10);
        toolBox.toFront();
        toolBox.setToolsEnabled(false);
        this.desktopPane.add(toolBox);
        closeBtn.setVisible(false);
    }

    /*
     * This function used to set add shape menu item enabled or not enabled
     */
    public void setMenuShapeToolsEnabled(boolean ena) {
        newShapeMenu.setEnabled(ena);
    }

    /*
     * This function used to reset menu items of the shape related to each
     * project type
     */
    public void resetMenuShapeTools(ProjectType projectType) {
        if (projectType.equals(ProjectType.PCR)) {
            bandMenuItem.setEnabled(true);
            dimerMenuItem.setEnabled(true);
            smearMenuItem.setEnabled(true);
            houseKeepingMenuItem.setEnabled(false);
        } else if (projectType.equals(ProjectType.MRNA)) {
            bandMenuItem.setEnabled(true);
            dimerMenuItem.setEnabled(false);
            smearMenuItem.setEnabled(false);
            houseKeepingMenuItem.setEnabled(true);
        } else if (projectType.equals(ProjectType.PRO)) {
            bandMenuItem.setEnabled(true);
            dimerMenuItem.setEnabled(true);
            smearMenuItem.setEnabled(false);
            houseKeepingMenuItem.setEnabled(false);
        }
    }

    /*
     * This function used to return ref to DualButton
     */
    public JButton getDualButton() {
        return dualButton;
    }

    /*
     * This Fuction used to return array containing pixels positions for 16
     * samples
     */
    public String getDescription() {
        return this.showInputDialog;
    }

    /*
     * This function used to return reference to positioning toolbar
     */
    public JPanel getPositioningToolbar() {
        return toolBoxPanel;
    }

    /*
     * This function return combobox containing samples number
     */
    public JComboBox getSampleCombo() {
        return samplesComboBox;
    }

    /*
     * This function used to set selected object on the win to change its
     * position as shown in toolbar
     */
    public void setSelectedShape(Shape shape) {
        selected = shape;
    }

    /*
     * This function used to get reference to setting logo button
     */
    public JButton getLogoBtn() {
        return addLogoBtn;
    }

    /*
     * This function used to get reference to setting company data button
     */
    public JButton getCompanyDataBtn() {
        return addCommentBtn;
    }

    /*
     * This function used to get selected object on the win to change its
     * position as shown in toolbar
     */
    public Shape getSeletedShape() {
        return selected;
    }

    /*
     * This function used to change textbox containing y position of the the
     * selected shape
     */
    public void setBandYPosition(String str) {
        this.positionTextField.setText(str);
    }
    /*
     * This is the variable of opened workarea(panel) and Function of getting
     * this panel
     */
    private JWorkArea workAreaPanel;

    public JWorkArea getOpenedWorkArea() {
        return workAreaPanel;
    }
    /*
     * This is the variable of opened workarea(frame) and Function of setting
     * selected workarea(frame)
     */
    private WorkArea selectedWorkArea = null;

    public void setSelectedWorkArea(WorkArea sel) {
        if (sel != null) {
            selectedWorkArea = sel;

            String sampleNumber = selectedWorkArea.getBandsPanel().getSampleType();
            this.getSelectedWorkArea().setSampleSize(Integer.parseInt(sampleNumber.split(" ")[0]));

            toolBox.setToolsEnabled(true);
        } else {
            toolBox.setToolsEnabled(false);
        }
    }

    /*
     * This function used to get Selected workarea (frame)
     */
    public WorkArea getSelectedWorkArea() {
        return selectedWorkArea;
    }

    /*
     * This function used to get reference to toolbox
     */
    public Toolbox getToolbox() {
        return toolBox;
    }

    /*
     * This function used to get reference to desktop pane
     */
    public JDesktopPane getDesktopPane() {
        return this.desktopPane;
    }
    int openedWorkAreaNum = 0;

    /*
     * This function used to set number of opened workareas and resetting
     * buttons according to it
     */
    public void setOpenedWorkAreaNum(int num) {
        openedWorkAreaNum = num;
        if (openedWorkAreaNum <= 0) {
            this.saveAsMenuItem.setEnabled(false);
            this.saveMenuItem.setEnabled(false);
            this.saveAsBtn.setEnabled(false);
            this.saveBtn.setEnabled(false);
            this.closeMenuItem.setEnabled(false);
            this.closeBtn.setEnabled(false);
            this.printPreviewBtn.setEnabled(false);
            this.printPreviewMenuItem.setEnabled(false);
            this.printBtn.setEnabled(false);
            this.printMenuItem1.setEnabled(false);

        } else if (openedWorkAreaNum > 0) {
            this.saveAsMenuItem.setEnabled(true);
            this.saveMenuItem.setEnabled(true);
            this.saveAsBtn.setEnabled(true);
            this.saveBtn.setEnabled(true);
            this.closeMenuItem.setEnabled(true);
            this.closeBtn.setEnabled(true);
            this.printPreviewBtn.setEnabled(true);
            this.printPreviewMenuItem.setEnabled(true);
            this.printBtn.setEnabled(true);
            this.printMenuItem1.setEnabled(true);
        }
    }

    /*
     * This function used to get number of opened workareas
     */
    public int getOpenedWorkAreaNum() {
        return openedWorkAreaNum;
    }

    /*
     * This function used to return reference to save as button
     */
    public JButton getSaveAsButton() {
        return saveAsBtn;
    }

    /*
     * This function used to enable or disable save button
     */
    public void setSaveEnabled(boolean flag) {
        saveBtn.setEnabled(flag);
        saveMenuItem.setEnabled(flag);
    }

    /*
     * This function used to change status of the editing buttons
     */
    public void setEditingButtonsEnable(boolean flag) {
        saveAsBtn.setEnabled(flag);
        saveAsMenuItem.setEnabled(flag);
        saveBtn.setEnabled(flag);
        saveMenuItem.setEnabled(flag);
        closeBtn.setEnabled(flag);
        closeMenuItem.setEnabled(flag);
        deleteBtn.setEnabled(flag);
        deleteMenuItem.setEnabled(flag);
        printBtn.setEnabled(flag);
        printMenuItem1.setEnabled(flag);
        printPreviewBtn.setEnabled(flag);
        printPreviewMenuItem.setEnabled(flag);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktopPane = new javax.swing.JDesktopPane();
        positioningToolBar = new javax.swing.JToolBar();
        jPanel1 = new javax.swing.JPanel();
        closeBtn = new javax.swing.JButton();
        printBtn = new javax.swing.JButton();
        deleteBtn = new javax.swing.JButton();
        saveAsBtn = new javax.swing.JButton();
        saveBtn = new javax.swing.JButton();
        openBtn = new javax.swing.JButton();
        printPreviewBtn = new javax.swing.JButton();
        addCommentBtn = new javax.swing.JButton();
        addLogoBtn = new javax.swing.JButton();
        dualButton = new javax.swing.JButton();
        toolBoxPanel = new javax.swing.JPanel();
        positionTextField = new javax.swing.JTextField();
        applyButton = new javax.swing.JButton();
        samplesComboBox = new javax.swing.JComboBox();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        newMenu = new javax.swing.JMenu();
        PCRMenuItem = new javax.swing.JMenuItem();
        sequencerMenuItem = new javax.swing.JMenuItem();
        mRNAMenuItem = new javax.swing.JMenuItem();
        protein = new javax.swing.JMenuItem();
        openMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        saveAsMenuItem = new javax.swing.JMenuItem();
        printPreviewMenuItem = new javax.swing.JMenuItem();
        printMenuItem1 = new javax.swing.JMenuItem();
        closeMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        deleteMenuItem = new javax.swing.JMenuItem();
        newShapeMenu = new javax.swing.JMenu();
        bandMenuItem = new javax.swing.JMenuItem();
        dimerMenuItem = new javax.swing.JMenuItem();
        smearMenuItem = new javax.swing.JMenuItem();
        houseKeepingMenuItem = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        viewMenu = new javax.swing.JMenu();
        toolbarMenu = new javax.swing.JMenu();
        formatCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
        toolboxMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        contentMenuItem = new javax.swing.JMenuItem();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Vacsera");
        setResizable(false);

        desktopPane.setAutoscrolls(true);

        positioningToolBar.setFloatable(false);
        positioningToolBar.setRollover(true);
        positioningToolBar.setVisible(true);

        closeBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Close.png"))); // NOI18N
        closeBtn.setToolTipText("Close Current Image");
        closeBtn.setEnabled(false);
        closeBtn.setFocusable(false);
        closeBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        closeBtn.setPreferredSize(new java.awt.Dimension(24, 24));
        closeBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        closeBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeMenuItemActionPerformed(evt);
            }
        });

        printBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Print.png"))); // NOI18N
        printBtn.setToolTipText("Print File");
        printBtn.setEnabled(false);
        printBtn.setFocusable(false);
        printBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        printBtn.setPreferredSize(new java.awt.Dimension(24, 24));
        printBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        printBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printPreviewMenuItemActionPerformed(evt);
            }
        });

        deleteBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Delete.png"))); // NOI18N
        deleteBtn.setToolTipText("Delete Shape");
        deleteBtn.setEnabled(false);
        deleteBtn.setFocusable(false);
        deleteBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        deleteBtn.setPreferredSize(new java.awt.Dimension(24, 24));
        deleteBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        deleteBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteMenuItemActionPerformed(evt);
            }
        });

        saveAsBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/SaveAs.png"))); // NOI18N
        saveAsBtn.setToolTipText("Save As");
        saveAsBtn.setEnabled(false);
        saveAsBtn.setFocusable(false);
        saveAsBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        saveAsBtn.setPreferredSize(new java.awt.Dimension(24, 24));
        saveAsBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        saveAsBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveAsMenuItemActionPerformed(evt);
            }
        });

        saveBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Save.png"))); // NOI18N
        saveBtn.setToolTipText("Save");
        saveBtn.setEnabled(false);
        saveBtn.setFocusable(false);
        saveBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        saveBtn.setPreferredSize(new java.awt.Dimension(24, 24));
        saveBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        saveBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });

        openBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Open.png"))); // NOI18N
        openBtn.setToolTipText("Open");
        openBtn.setFocusable(false);
        openBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        openBtn.setPreferredSize(new java.awt.Dimension(24, 24));
        openBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        openBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });

        printPreviewBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/PrintPreview.png"))); // NOI18N
        printPreviewBtn.setToolTipText("Print Preview");
        printPreviewBtn.setEnabled(false);
        printPreviewBtn.setFocusable(false);
        printPreviewBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        printPreviewBtn.setPreferredSize(new java.awt.Dimension(24, 24));
        printPreviewBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        printPreviewBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printPreviewBtnActionPerformed(evt);
            }
        });

        addCommentBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Comment.png"))); // NOI18N
        addCommentBtn.setToolTipText("Add Company Data");
        addCommentBtn.setEnabled(false);
        addCommentBtn.setPreferredSize(new java.awt.Dimension(24, 24));
        addCommentBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addCommentBtnActionPerformed(evt);
            }
        });

        addLogoBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Picture.png"))); // NOI18N
        addLogoBtn.setToolTipText("Add Company Logo");
        addLogoBtn.setEnabled(false);
        addLogoBtn.setPreferredSize(new java.awt.Dimension(24, 24));
        addLogoBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addLogoBtnActionPerformed(evt);
            }
        });

        dualButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/stats.png"))); // NOI18N
        dualButton.setToolTipText("Close Current Image");
        dualButton.setBorderPainted(false);
        dualButton.setEnabled(false);
        dualButton.setFocusable(false);
        dualButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        dualButton.setPreferredSize(new java.awt.Dimension(24, 24));
        dualButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        dualButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dualButtoncloseMenuItemActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(openBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(saveBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(saveAsBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(deleteBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(printPreviewBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(printBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(addCommentBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(addLogoBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dualButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 98, Short.MAX_VALUE)
                .addComponent(closeBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(115, 115, 115))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 2, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dualButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(addLogoBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(addCommentBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saveAsBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saveBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(openBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(deleteBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(printBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(printPreviewBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(closeBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        positioningToolBar.add(jPanel1);

        positionTextField.setToolTipText("Select position related to The Marker");
        positionTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                positionTextFieldKeyPressed(evt);
            }
        });

        applyButton.setText("Apply");
        applyButton.setToolTipText("Apply Changes");
        applyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                applyButtonActionPerformed(evt);
            }
        });

        samplesComboBox.setToolTipText("Select Sample");

        javax.swing.GroupLayout toolBoxPanelLayout = new javax.swing.GroupLayout(toolBoxPanel);
        toolBoxPanel.setLayout(toolBoxPanelLayout);
        toolBoxPanelLayout.setHorizontalGroup(
            toolBoxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(toolBoxPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(samplesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(positionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(applyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        toolBoxPanelLayout.setVerticalGroup(
            toolBoxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(toolBoxPanelLayout.createSequentialGroup()
                .addGroup(toolBoxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(positionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(applyButton)
                    .addComponent(samplesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        toolBoxPanel.setVisible(false);
        positioningToolBar.add(toolBoxPanel);

        fileMenu.setMnemonic('f');
        fileMenu.setText("File");

        newMenu.setText("New");

        PCRMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        PCRMenuItem.setText("PCR");
        PCRMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PCRMenuItemActionPerformed(evt);
            }
        });
        newMenu.add(PCRMenuItem);

        sequencerMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        sequencerMenuItem.setText("Sequencer");
        sequencerMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sequencerMenuItemActionPerformed(evt);
            }
        });
        newMenu.add(sequencerMenuItem);

        mRNAMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mRNAMenuItem.setText("mRNA");
        mRNAMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mRNAMenuItemActionPerformed(evt);
            }
        });
        newMenu.add(mRNAMenuItem);

        protein.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        protein.setText("Protein Image");
        protein.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                proteinActionPerformed(evt);
            }
        });
        newMenu.add(protein);

        fileMenu.add(newMenu);

        openMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        openMenuItem.setMnemonic('o');
        openMenuItem.setText("Open");
        openMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(openMenuItem);

        saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveMenuItem.setMnemonic('s');
        saveMenuItem.setText("Save");
        saveMenuItem.setEnabled(false);
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveMenuItem);

        saveAsMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        saveAsMenuItem.setMnemonic('a');
        saveAsMenuItem.setText("Save As ...");
        saveAsMenuItem.setDisplayedMnemonicIndex(5);
        saveAsMenuItem.setEnabled(false);
        saveAsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveAsMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveAsMenuItem);

        printPreviewMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        printPreviewMenuItem.setText("Print Preview");
        printPreviewMenuItem.setEnabled(false);
        printPreviewMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printPreviewMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(printPreviewMenuItem);

        printMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        printMenuItem1.setText("Print");
        printMenuItem1.setEnabled(false);
        printMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printMenuItem1ActionPerformed(evt);
            }
        });
        fileMenu.add(printMenuItem1);

        closeMenuItem.setText("Close");
        closeMenuItem.setEnabled(false);
        closeMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeMenuItemActionPerformed1(evt);
            }
        });
        fileMenu.add(closeMenuItem);

        exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        editMenu.setMnemonic('e');
        editMenu.setText("Edit");

        deleteMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        deleteMenuItem.setMnemonic('d');
        deleteMenuItem.setText("Delete");
        deleteMenuItem.setEnabled(false);
        deleteMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteMenuItemActionPerformed(evt);
            }
        });
        editMenu.add(deleteMenuItem);

        newShapeMenu.setText("Add Shape");
        newShapeMenu.setEnabled(false);

        bandMenuItem.setText("Band");
        bandMenuItem.setEnabled(false);
        bandMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bandMenuItemActionPerformed(evt);
            }
        });
        newShapeMenu.add(bandMenuItem);

        dimerMenuItem.setText("Dimer");
        dimerMenuItem.setEnabled(false);
        newShapeMenu.add(dimerMenuItem);

        smearMenuItem.setText("Smear");
        smearMenuItem.setEnabled(false);
        newShapeMenu.add(smearMenuItem);

        houseKeepingMenuItem.setText("Housekeeping");
        houseKeepingMenuItem.setEnabled(false);
        newShapeMenu.add(houseKeepingMenuItem);

        editMenu.add(newShapeMenu);

        jMenuItem1.setText("Resource Manager");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        editMenu.add(jMenuItem1);

        menuBar.add(editMenu);

        viewMenu.setMnemonic('V');
        viewMenu.setText("View");

        toolbarMenu.setText("Toolbars");

        formatCheckBoxMenuItem.setSelected(true);
        formatCheckBoxMenuItem.setText("Standard");
        formatCheckBoxMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                formatCheckBoxMenuItemActionPerformed(evt);
            }
        });
        toolbarMenu.add(formatCheckBoxMenuItem);

        viewMenu.add(toolbarMenu);

        toolboxMenuItem.setText("Toolbox");
        toolboxMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                toolboxMenuItemActionPerformed(evt);
            }
        });
        viewMenu.add(toolboxMenuItem);

        menuBar.add(viewMenu);

        helpMenu.setMnemonic('h');
        helpMenu.setText("Help");

        contentMenuItem.setMnemonic('c');
        contentMenuItem.setText("Contents");
        contentMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                contentMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(contentMenuItem);

        aboutMenuItem.setText("About");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane)
            .addComponent(positioningToolBar, javax.swing.GroupLayout.DEFAULT_SIZE, 1040, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(positioningToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    //this Method to assign the value of brightness to the selected band in mRNA
    public void setSelectedBandBrightness() {
        inputDialog = (String) JOptionPane.showInputDialog(this, "Enter the value of brightness", "Set brightness of selected band", 0, null, null, null);
        try {
            int brightnessValue = Integer.parseInt(inputDialog);
            Band curBand = (Band) this.selected;
            curBand.setBrightness(brightnessValue);
        } catch (Exception ex) {
        }
    }

    /*
     * This function used to perform print preview on the active window
     */
    private void printPreview() {
        JInternalFrame jframe = this.getDesktopPane().getSelectedFrame();
        JPanel win = null;
        if (jframe.getClass().getName().equals("PCR.Sequencer")) {
            Sequencer temp = (Sequencer) jframe;
            win = temp.getDrawCurve();
        } else if (jframe.getClass().getName().equals("PCR.WorkArea")) {
            WorkArea temp = (WorkArea) jframe;
            win = temp.getBandsPanel();
        }
        Dimension size = win.getSize();
        BufferedImage image = (BufferedImage) win.createImage(size.width, size.height);
        Graphics g = image.getGraphics();
        win.paint(g);
        JPrintPrivewFrame frm = new JPrintPrivewFrame();

        PrintPreviewer prntpver = new PrintPreviewer(image);

        frm.setPanel(prntpver);
        frm.setJScrollPanel();
        prntpver.setSize(500, frm.getPrivewArea().getSize().height);;
        int a = frm.getPrivewArea().getSize().width / 2 - prntpver.getSize().width / 2;
        int b = frm.getPrivewArea().getSize().height / 2 - prntpver.getSize().height / 2;

        prntpver.setLocation(a, b);

        prntpver.setZoomStatus(frm.maginfingStatus());

        frm.getPrivewArea().setFocusable(false);
        frm.getPrivewArea().getViewport().add(prntpver);
        frm.getPrivewArea().setAutoscrolls(true);

        frm.setVisible(true);
        frm.setResizable(true);
        frm.setMaximizable(true);
        frm.setIconifiable(true);
        frm.setClosable(true);
        this.desktopPane.add(frm);
        frm.toFront();
    }
    private void printPreviewMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printPreviewMenuItemActionPerformed
        ImagePrinter.printImage(this.getSelectedWorkArea().getBandsPanel());
    }//GEN-LAST:event_printPreviewMenuItemActionPerformed

    private void PCRMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PCRMenuItemActionPerformed
        pcr = new NewPCR();
        pcr.setVisible(true);
        desktopPane.add(pcr);
        try {
            pcr.setSelected(true);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_PCRMenuItemActionPerformed

    private void closeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeMenuItemActionPerformed
        if (pcr != null) {
            pcr.getWorkArea().doDefaultCloseAction();
        }
    }//GEN-LAST:event_closeMenuItemActionPerformed

    private void sequencerMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sequencerMenuItemActionPerformed
        seq = new NewSequencer();
        seq.setVisible(true);
        desktopPane.add(seq);
        try {
            seq.setSelected(true);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_sequencerMenuItemActionPerformed

    private void mRNAMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mRNAMenuItemActionPerformed
        NewmRNA mrna = new NewmRNA();
        mrna.setVisible(true);
        desktopPane.add(mrna);
        try {
            mrna.setSelected(true);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_mRNAMenuItemActionPerformed

    private void toolboxMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_toolboxMenuItemActionPerformed
        toolBox.setVisible(true);
        toolBox.setSize(200, 600);
        toolBox.setLocation(10, 40);
        toolBox.toFront();
    }//GEN-LAST:event_toolboxMenuItemActionPerformed

    private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed
        // TODO add your handling code here:
        int y;
        if (selected != null) {

            int sampleNu = (int) samplesComboBox.getSelectedItem();
            int position = 0;
            y = Integer.parseInt(positionTextField.getText());

            if (positionTextField.getText().isEmpty()) {
                JOptionPane.showMessageDialog(null, "Please Enter Band Position.");

            } else if (y < this.getSelectedWorkArea().getMarkerType() || y > this.getSelectedWorkArea().getBandsPanel().getSize().height) {
                JOptionPane.showMessageDialog(null, "Shape position out of the marker boundry!");
            } else {
                if (samplesComboBox.getItemCount() == 16) {
                    position = this.getSelectedWorkArea().get16Position()[sampleNu];
                } else if (samplesComboBox.getItemCount() == 8) {
                    position = this.getSelectedWorkArea().get8Position()[sampleNu];
                } else if (samplesComboBox.getItemCount() == 4) {
                    position = this.getSelectedWorkArea().get4Position()[sampleNu];
                }
                getSeletedShape().setLocation(position, this.getSelectedWorkArea().getBandsPanel().getSize().height - Integer.parseInt(this.positionTextField.getText()) - this.getSeletedShape().getSize().height);
                getSeletedShape().setCurSample(sampleNu);
                this.getSelectedWorkArea().getBandsPanel().revalidate();
            }

        } else {
            JOptionPane.showMessageDialog(null, "Please select a Band First.");
        }
    }//GEN-LAST:event_applyButtonActionPerformed
    Vector<File> openFiles = new Vector<File>();

    public Vector<File> getOpenedFiles() {
        return openFiles;
    }

    private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
        try {

            JFileChooser jfc = new JFileChooser();
            ExtensionFileFilter filesFilterPCR = new ExtensionFileFilter("Vacsera Files(PCR)", new String[]{"pcr"});
            ExtensionFileFilter filesFilterMRNA = new ExtensionFileFilter("Vacsera Files(MRNA)", new String[]{"mrna"});
            jfc.setFileFilter(filesFilterPCR);

            jfc.addChoosableFileFilter(filesFilterPCR);
            jfc.addChoosableFileFilter(filesFilterMRNA);

            jfc.setFileFilter(filesFilterPCR);

            if (jfc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                if (jfc.getSelectedFile().exists()) {
                    if (openFiles.contains(jfc.getSelectedFile())) {

                        JOptionPane.showMessageDialog(null, "That file already opened!");

                        return;
                    }

                    if (jfc.getSelectedFile().getPath().isEmpty()) {
                        JOptionPane.showMessageDialog(null, "Please enter File Name");
                    } else {
                        String path = jfc.getSelectedFile().getPath();
                        FileInputStream fis = new FileInputStream(path);
                        ObjectInputStream ois = new ObjectInputStream(fis);
                        JWorkArea work = (JWorkArea) ois.readObject();
                        ois.close();
                        work.getShapeMenu().getDeleteItem().addActionListener(new MenuAction());
                        work.getShapeMenu().getResetItem().addActionListener(new MenuAction());
                        work.getShapeMenu().getMoveItem().addActionListener(new CheckMenuAction());
                        work.getShapeMenu().getBringtoFrontItem().addActionListener(new MenuAction());
                        work.getShapeMenu().getSendtoBack().addActionListener(new MenuAction());
                        work.getShapeMenu().getBrightnessItem().addActionListener(new MenuAction());
                        work.getShapeMenu().addPopupMenuListener(new ShapeMenuActions());
                        if (work.getProjectType() == ProjectType.PCR) {
                            for (Component co : work.getComponents()) {
                                if (co instanceof Band || co instanceof Dimer || co instanceof Smear) {
                                    Shape sh = (Shape) co;
                                    sh.addMouseListener(new ShapeMouseAction());
                                    sh.addMouseMotionListener(new ShapeMouseMotionAction());
                                    sh.addFocusListener(new ShapeFocusHandler());
                                }
                            }

                        } else if (work.getProjectType() == ProjectType.MRNA) {
                            for (Component co : work.getComponents()) {
                                if (co instanceof Band || co instanceof HouseKeeping) {
                                    Shape sh = (Shape) co;
                                    sh.addMouseListener(new ShapeMouseAction());
                                    sh.addMouseMotionListener(new ShapeMouseMotionAction());
                                    sh.addFocusListener(new ShapeFocusHandler());
                                }
                            }
                        }

                        workAreaPanel = work;

                        String sampleNumber = workAreaPanel.getSampleType();

                        String markerType;
                        toolBoxPanel.setVisible(true);
                        WorkArea workArea = new WorkArea(jfc.getName(jfc.getSelectedFile()), false, work.getProjectType().toString());
                        workArea.setTitle(jfc.getName(jfc.getSelectedFile()));
                        workArea.setVisible(true);
                        workArea.setSize(800, 600);
                        workArea.setLocation(220, 40);
                        workArea.toFront();
                        workArea.setOpenedProject(true);
                        workArea.setSavedPath(jfc.getSelectedFile());
                        workArea.setProjectType(workAreaPanel.getProjectType());
                        this.setSelectedWorkArea(workArea);
                        desktopPane.add(workArea);
                        openFiles.add(jfc.getSelectedFile());
                        openedWorkAreaNum++;
                    }
                }
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "That file may be damaged! so can't read that file");

        }

    }//GEN-LAST:event_openMenuItemActionPerformed
    /*
     * This function used to check title of the frame
     */

    private String CheckTitle(String text) {
        if (text.equals("Untitled") || text.equals("")) {
            text = "Untitled";
        } else if (text.endsWith(".pcr")) {
            text = text.substring(0, text.length() - 4);
        }
        return text;
    }
    private void saveAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsMenuItemActionPerformed
        //TODO code
        JInternalFrame jframe = this.getDesktopPane().getSelectedFrame();
        String title = jframe.getTitle();
        CustomFileChooser fc = new CustomFileChooser();
        fc.setDialogTitle("Save As");
        fc.setAcceptAllFileFilterUsed(false);
        FileNameExtensionFilter jpegFilter = new FileNameExtensionFilter("JPEG file extension", "jpg", "jpeg");
        FileNameExtensionFilter pngFilter = new FileNameExtensionFilter("PNG file extension", "png");
        FileNameExtensionFilter bmpFilter = new FileNameExtensionFilter("BMP file extension", "bmp");

        fc.addChoosableFileFilter(jpegFilter);
        fc.addChoosableFileFilter(pngFilter);
        fc.addChoosableFileFilter(bmpFilter);

        fc.setSelectedFile(new File(CheckTitle(title)));
        if (fc.showSaveDialog(MainFrame.this) == JFileChooser.APPROVE_OPTION) {
            JPanel win = null;
            Dimension size = null;
            if (jframe.getClass().getName().equals("PCR.Sequencer")) {
                Sequencer temp = (Sequencer) jframe;
                temp.setSaved(true);
                win = temp.getDrawCurve();
                size = win.getSize();
            } else if (jframe.getClass().getName().equals("PCR.WorkArea")) {
                WorkArea temp = (WorkArea) jframe;
                temp.setSaved(true);
                win = temp.getBandsPanel();
                size = win.getSize();
            }
            BufferedImage image = (BufferedImage) win.createImage(size.width, size.height);
            Graphics g = image.getGraphics();
            win.paint(g);
            g.dispose();
            try {
                String fname = fc.getSelectedFile().getName();
                String ext = fc.getFileFilter().getDescription().split(" ")[0].toLowerCase();
                ImageIO.write(image, ext, fc.getSelectedFile());
                jframe.setTitle(fc.getSelectedFile().getName());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }//GEN-LAST:event_saveAsMenuItemActionPerformed

    private void formatCheckBoxMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formatCheckBoxMenuItemActionPerformed
        // TODO add your handling code here:
        if (formatCheckBoxMenuItem.isSelected() == true) {
            jPanel1.setVisible(true);
        } else {
            jPanel1.setVisible(false);
        }
    }//GEN-LAST:event_formatCheckBoxMenuItemActionPerformed

    /*
     * This function used to set file name that will be saved According to
     * project type
     */
    private String setSavedFileName(String fileName) {
        String fName = fileName;
        if (selectedWorkArea.getProjectType() == ProjectType.PCR) {
            if (fName.endsWith(".pcr")) {
                return fileName;
            } else {
                return fileName + ".pcr";
            }
        } else if (selectedWorkArea.getProjectType() == ProjectType.MRNA) {
            if (fName.endsWith(".mrna")) {
                return fileName;
            } else {
                return fileName + ".mrna";
            }
        } else if (selectedWorkArea.getProjectType() == ProjectType.PRO) {
            if (fName.endsWith(".pro")) {
                return fileName;
            } else {
                return fileName + ".pro";
            }
        }
        return fName;
    }
    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
        //TODO
        try {
            if (this.getSelectedWorkArea() != null) {
                {
                    CustomFileChooser jfc = new CustomFileChooser();
                    jfc.setAcceptAllFileFilterUsed(false);
                    ExtensionFileFilter filesFilterPCR = new ExtensionFileFilter("Vacsera Files(PCR)", new String[]{"pcr"});
                    ExtensionFileFilter filesFilterMRNA = new ExtensionFileFilter("Vacsera Files(MRNA)", new String[]{"mrna"});
                    ExtensionFileFilter filesFilterPRO = new ExtensionFileFilter("Vacsera Files(PRO)", new String[]{"pro"});

                    jfc.addChoosableFileFilter(filesFilterPCR);
                    jfc.addChoosableFileFilter(filesFilterMRNA);
                    jfc.addChoosableFileFilter(filesFilterPRO);

                    if (selectedWorkArea.getProjectType() == ProjectType.PCR) {
                        jfc.setFileFilter(filesFilterPCR);
                    } else if (selectedWorkArea.getProjectType() == ProjectType.MRNA) {
                        jfc.setFileFilter(filesFilterMRNA);
                    } else if (selectedWorkArea.getProjectType() == ProjectType.PRO) {
                        jfc.setFileFilter(filesFilterPRO);
                    }
                    jfc.setSelectedFile(new File(setSavedFileName(this.getSelectedWorkArea().getTitle())));
                    if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
                        getSelectedWorkArea().getBandsPanel().setProjectType(getSelectedWorkArea().getProjectType());
                        this.getSelectedWorkArea().setSavedPath(jfc.getSelectedFile());
                        FileOutputStream fos = new FileOutputStream(jfc.getSelectedFile());
                        ObjectOutputStream os = new ObjectOutputStream(fos);
                        os.writeObject(this.getSelectedWorkArea().getBandsPanel());
                        os.flush();
                        os.close();
                    }
                }
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_saveMenuItemActionPerformed

    private void deleteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteMenuItemActionPerformed
        // TODO add your handling code here:
        if (this.getSeletedShape() != null) {
            this.getSeletedShape().getParent().remove(getSeletedShape());
            this.repaint();
            this.setSelectedShape(null);
        } else {
            JOptionPane.showMessageDialog(null, "Please select a Shape First.");
        }
    }//GEN-LAST:event_deleteMenuItemActionPerformed

    private void positionTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_positionTextFieldKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            applyButton.doClick();
        }
    }//GEN-LAST:event_positionTextFieldKeyPressed

    private void closeMenuItemActionPerformed1(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeMenuItemActionPerformed1
        if (this.getSelectedWorkArea() != null) {
            this.getSelectedWorkArea().closeWindow();
            int num = this.getOpenedWorkAreaNum() - 1;
            this.setOpenedWorkAreaNum(num);
        }
    }//GEN-LAST:event_closeMenuItemActionPerformed1

    private void printMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printMenuItem1ActionPerformed
        JInternalFrame jframe = this.getDesktopPane().getSelectedFrame();
        JPanel panel = null;
        if (jframe.getClass().getName().equals("PCR.Sequencer")) {
            Sequencer temp = (Sequencer) jframe;
            panel = temp.getDrawCurve();
        } else if (jframe.getClass().getName().equals("PCR.WorkArea")) {
            WorkArea temp = (WorkArea) jframe;
            panel = temp.getBandsPanel();
        }
        ImagePrinter.printImage(panel);
    }//GEN-LAST:event_printMenuItem1ActionPerformed

    private void printPreviewBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printPreviewBtnActionPerformed
        printPreview();
    }//GEN-LAST:event_printPreviewBtnActionPerformed

    private void proteinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_proteinActionPerformed

        Newprotein = new NewPro();
        Newprotein.setVisible(true);
        desktopPane.add(Newprotein);

        try {
            Newprotein.setSelected(true);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_proteinActionPerformed

    private void addCommentBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addCommentBtnActionPerformed
        // TODO add your handling code here:
        inputDialog = JOptionPane.showInputDialog("Put your message here :");
        Sequencer temp = (Sequencer) getDesktopPane().getSelectedFrame();
        temp.getDrawCurve().getTitleLabel().setText(inputDialog);
    }//GEN-LAST:event_addCommentBtnActionPerformed

    private void addLogoBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addLogoBtnActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        FileNameExtensionFilter filter = new FileNameExtensionFilter(".jpg , .png ,jpeg files", "png", "jpg", "jpeg");
        chooser.setFileFilter(filter);
        int code = chooser.showOpenDialog(null);
        if (code == JFileChooser.APPROVE_OPTION) {
            try {
                File selectedFile = chooser.getSelectedFile();
                Scanner input = new Scanner(selectedFile);
                while (input.hasNext()) {
                    input.next();
                }
                Icon icn = new javax.swing.ImageIcon(selectedFile.getPath());
                Image img = ((ImageIcon) icn).getImage();
                ImageIcon icon = new ImageIcon(img.getScaledInstance(100, 100, Image.SCALE_AREA_AVERAGING));
                Sequencer temp = (Sequencer) getDesktopPane().getSelectedFrame();
                temp.getDrawCurve().getTitleLabelImage().setIcon(icon);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_addLogoBtnActionPerformed

    private void bandMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bandMenuItemActionPerformed
        // TODO add your handling code here:
        JMenuItem menu = (JMenuItem) evt.getSource();
        ShapesDialog shd = new ShapesDialog(this, true);
        ShapesDialog.setReplacer(false);
        shd.loadShapes(menu.getText());
        shd.setVisible(true);
    }//GEN-LAST:event_bandMenuItemActionPerformed

    private void dualButtoncloseMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dualButtoncloseMenuItemActionPerformed
        DualAxisChart dac = new DualAxisChart(" ");
        dac.pack();
        RefineryUtilities.centerFrameOnScreen(dac);
        dac.setVisible(true);

    }//GEN-LAST:event_dualButtoncloseMenuItemActionPerformed

    private void contentMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contentMenuItemActionPerformed

        String htmlFilePath = "resources/vh.htm"; // path to your new file
        File htmlFile = new File(htmlFilePath);

        try {
// open the default web browser for the HTML page
           // Desktop.getDesktop().browse(htmlFile.toURI());
          //  Runtime.getRuntime().exec("/home/icdev/NetBeansProjects/itigraduation/resources/before.html");
// if a web browser is the default HTML handler, this might lwork too
Desktop.getDesktop().open(htmlFile);
        } catch (Exception e) {
            System.out.println("Cannot open help");
            e.printStackTrace();
        }
    }//GEN-LAST:event_contentMenuItemActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        About abt = new About();
        abt.setVisible(true);
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        JResourcesManager resmgr = new JResourcesManager();
        this.desktopPane.add(resmgr);
        resmgr.setSize(new Dimension(570, 600));
        resmgr.setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem PCRMenuItem;
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JButton addCommentBtn;
    private javax.swing.JButton addLogoBtn;
    private javax.swing.JButton applyButton;
    private javax.swing.JMenuItem bandMenuItem;
    private javax.swing.JButton closeBtn;
    private javax.swing.JMenuItem closeMenuItem;
    private javax.swing.JMenuItem contentMenuItem;
    private javax.swing.JButton deleteBtn;
    private javax.swing.JMenuItem deleteMenuItem;
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JMenuItem dimerMenuItem;
    private javax.swing.JButton dualButton;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JCheckBoxMenuItem formatCheckBoxMenuItem;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JMenuItem houseKeepingMenuItem;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JMenuItem mRNAMenuItem;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenu newMenu;
    private javax.swing.JMenu newShapeMenu;
    private javax.swing.JButton openBtn;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JTextField positionTextField;
    private javax.swing.JToolBar positioningToolBar;
    private javax.swing.JButton printBtn;
    private javax.swing.JMenuItem printMenuItem1;
    private javax.swing.JButton printPreviewBtn;
    private javax.swing.JMenuItem printPreviewMenuItem;
    private javax.swing.JMenuItem protein;
    private javax.swing.JComboBox samplesComboBox;
    private javax.swing.JButton saveAsBtn;
    private javax.swing.JMenuItem saveAsMenuItem;
    private javax.swing.JButton saveBtn;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JMenuItem sequencerMenuItem;
    private javax.swing.JMenuItem smearMenuItem;
    private javax.swing.JPanel toolBoxPanel;
    private javax.swing.JMenu toolbarMenu;
    private javax.swing.JMenuItem toolboxMenuItem;
    private javax.swing.JMenu viewMenu;
    // End of variables declaration//GEN-END:variables
}
